﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Meow.Core;

public class Res_Mesh
{
    public readonly int Version;
    public readonly int VertexCount;

    public byte[] data;

    public readonly static string FallbackPath = Path.Combine(MeowPath.DefaultMeshPath, "_error.mmr");

    public readonly static Dictionary<string, Res_Mesh> Dict_PathMesh = new Dictionary<string, Res_Mesh>();

   /// <summary>
   /// WIP
   /// </summary>
    Res_Mesh(string path)
    {
        if (!Path.Exists(path))
        {
            Logger.Error("Can't find mesh at " + path);
            path = FallbackPath;
        }

        var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
        Version = fs.ReadInt32();
    }

    /// <summary>
    /// WIP
    /// </summary>
    public static Res_Mesh Load(string path)
    {
        if (Dict_PathMesh.TryGetValue(path, out Res_Mesh resMesh)) { return resMesh; }
        else
        {
            return new Res_Mesh(path);
        }
    }
}
